<style lang="scss">
.issue-container {
  .paste-btn-div {
    margin-top: 5px;
    text-align: center;
  }
  .gdxx-div {
    outline: 1px dotted #cccccc;
    padding-top: 7px;
    margin-top: 7px;
  }
  .my_model_style {
    .el-dialog__header {
      padding: 15px;
      // background-color: #ECF5FF;
      text-align: center;
      font-size: 18px !important;
    }
  }
  .tabFontSize {
    font-size: 14px;
  }
}
</style>

<template>
  <!-- 工单维护-已下发 -->
  <el-container class="issue-container">
    <!-- 顶栏容器 -->
    <el-header>
      <!-- 查询框 -->
      <div class="search-box">
        <div class="conditions-box">
          <div class="conditions-item">
            年度:
            <el-select
              v-model="pageParam.condition.govYear"
              size="small"
              :clearable="true"
              placeholder="请选择年度"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="(item, index) in yearList"
                :key="index"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </div>
          <div class="conditions-item">
            工单编号:
            <el-input
              v-model="pageParam.condition.code"
              size="small"
              :clearable="true"
              placeholder="请输入工单编号"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            工单内容:
            <el-input
              v-model="pageParam.condition.content"
              size="small"
              :clearable="true"
              placeholder="请输入内容关键字"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            工单来源:
            <el-select
              v-model="pageParam.condition.sourceId"
              size="small"
              :clearable="true"
              placeholder="请选择工单来源"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="item in sourceList"
                :key="item.lyid"
                :label="item.lymc"
                :value="item.lyid"
              ></el-option>
            </el-select>
          </div>
          <div class="conditions-item">
            执行处室:
            <el-select
              v-model="pageParam.condition.deptId"
              size="small"
              :clearable="true"
              placeholder="请选择执行处室"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="item in deptList"
                :key="item.bmid"
                :label="item.bmjc"
                :value="item.bmid"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div class="search-btn">
          <el-button
            size="small"
            icon="el-icon-search"
            plain
            @click="doSearch"
            :loading="loadingTable"
            >查询</el-button
          >
          <el-button
            type="primary"
            size="small"
            icon="el-icon-circle-plus-outline"
            plain
            @click="addFn"
            >添加</el-button
          >
        </div>
      </div>
    </el-header>
    <!-- 主要区域容器 -->
    <el-main>
      <el-table
        :data="tableItem.list"
        stripe
        border
        :height="tableHeight"
        v-loading="loadingTable"
      >
        <el-table-column
          prop="code"
          label="工单编号"
          align="left"
          show-overflow-tooltip
          width="180"
        ></el-table-column>
        <el-table-column
          prop="sourceName"
          label="来源系统"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="szxx_type_sub"
          label="工单来源"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="cateName"
          label="工单类别"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="deptName"
          label="执行处室"
          align="center"
        ></el-table-column>
        <el-table-column prop="repeated" label="重复件" align="center" width="60">
          <template slot-scope="scope">
            <i
              v-if="scope.row.repeated === 1"
              class="el-icon-refresh"
              style="color: red; font-size: 16px;"
            ></i>
            <i
              v-else
              class="el-icon-refresh"
              style="color: grey; font-size: 16px;"
            ></i>
          </template>
        </el-table-column>
        <el-table-column prop="important" label="紧急件" align="center" width="60">
          <template slot-scope="scope">
            <i
              v-if="scope.row.important === 1"
              class="el-icon-star-off"
              style="color: red; font-size: 16px;"
            ></i>
            <i
              v-else
              class="el-icon-star-off"
              style="color: grey; font-size: 16px;"
            ></i>
          </template>
        </el-table-column>
        <el-table-column prop="situation" label="疫情件" align="center" width="60">
          <template slot-scope="scope">
            <i
              v-if="scope.row.situation === true"
              class="el-icon-s-help"
              style="color: red; font-size: 16px;"
            ></i>
            <i
              v-else
              class="el-icon-s-help"
              style="color: grey; font-size: 16px;"
            ></i>
          </template>
        </el-table-column>
        <el-table-column
          prop="firstTime"
          label="下发时间"
          align="center"
          :formatter="formatDate"
          width="230"
        ></el-table-column>
        <el-table-column prop="dqzt" label="当前状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.dqzt === 2" class="tabFontSize">待分发</span>
            <span v-else-if="scope.row.dqzt === 3" class="tabFontSize"
              >待办理</span
            >
            <span v-else-if="scope.row.dqzt === 4" class="tabFontSize"
              >已办理</span
            >
            <span v-else-if="scope.row.dqzt === 5" class="tabFontSize"
              >已退回</span
            >
            <span v-else-if="scope.row.dqzt === 6" class="tabFontSize"
              >已结束</span
            >
            <span v-else-if="scope.row.dqzt === 7" class="tabFontSize"
              >已审核</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="operations"
          label="操作"
          align="right"
          width="210"
        >
          <template slot-scope="scope">
            <el-button
              v-for="(item, index) in scope.row.operationsModelList"
              :key="index"
              :type="item.type"
              plain
              size="mini"
              :icon="item.icon"
              v-bind:class="'operations-' + item.handleMethod"
              @click="operationClick(item.handleMethod, scope.row)"
              >{{ item.label }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="tableItem.pageNum"
        :page-size="tableItem.pageSize"
        :page-sizes="[20, 30, 50, 100]"
        :total="tableItem.total"
        layout="total, sizes, prev, pager, next, jumper"
        style="float: right;"
      ></el-pagination>
    </el-main>

    <!-- 已下发查看详情 -->
    <el-dialog
      class="my_model_style"
      title="工单查看"
      :visible.sync="dialogIssuedDetail"
      width="100%"
      :fullscreen="fullScreen"
      :before-close="dialogIssuedCloseFn"
    >
      <issued-detail
        v-if="dialogIssuedDetail"
        ref="issuedDetail"
        v-bind:wllzid="wllzid"
      ></issued-detail>
    </el-dialog>
  </el-container>
</template>

<script>
import issuedDetail from './service-issued-detail.vue'

export default {
  name: 'service-issue',
  data () {
    return {
      // 主键id
      wllzid: '',
      // 年度列表
      yearList: [],
      // 来源列表
      sourceList: [],
      // 处室列表
      deptList: [],
      // 查询参数
      pageParam: {
        pageNum: 1,
        pageSize: 20,
        condition: {
          govYear: '',
          deptId: '',
          sourceId: '',
          code: '',
          content: ''
        }
      },
      loadingTable: false,
      // 表格高度
      tableHeight: -1,
      // 表格列表
      tableItem: {},
      // 已下发查看
      dialogIssuedDetail: false,
      fullScreen: true
    }
  },
  methods: {
    // 获取年度列表
    getYearList () {
      this.$axios.post(this.$api.common.yearList).then(rs => {
        if (rs) {
          this.yearList = rs
          // this.pageParam.condition.govYear = rs[0]
        }
      })
    },
    // 获取来源列表
    getSourceList () {
      this.$axios.post(this.$api.source.selector).then(rs => {
        if (rs) {
          this.sourceList = rs
        }
      })
    },
    // 获取责任处室
    getDeptList () {
      this.$axios.post(this.$api.dept.selector).then(rs => {
        if (rs) {
          this.deptList = rs
        }
      })
    },
    // 查询方法
    doSearch () {
      this.loadingTable = true
      this.getIssuePage()
    },
    // 获取督办分页列表
    getIssuePage () {
      this.$axios.post(this.$api.service.issuePage, this.pageParam).then(rs => {
        if (rs) {
          this.tableItem = rs
          this.loadingTable = false
        }
      })
    },
    // 分页
    handleSizeChange: function (size) {
      this.pageParam.pageSize = size
      this.loadingTable = true
      this.getIssuePage()
    },
    // 分页
    handleCurrentChange: function (currentPage) {
      this.pageParam.pageNum = currentPage
      this.loadingTable = true
      this.getIssuePage()
    },
    // 日期格式化
    formatDate: function (row, column) {
      const _this = this
      var date = row.firstTime
      if (date === undefined) {
        return ''
      }
      return _this.$moment(date).format('YYYY年MM月DD日 HH时mm分')
    },
    // 操作点击事件
    operationClick (method, row) {
      switch (method) {
        case 'revoke':
          this.revokeFn(row)
          break
        case 'detail':
          this.detailFn(row)
          break
      }
    },
    // 添加工单
    addFn () {
      this.$router.push('/serviceEdit')
    },
    // 撤回工单
    revokeFn: function (item) {
      const _this = this
      _this
        .$confirm('即将撤回工单，是否继续?', '提示', {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          type: 'warning'
        })
        .then(() => {
          this.loadingTable = true
          _this.$axios
            .get(_this.$api.service.revoke + '/' + item.wllzid)
            .then(function (rs) {
              if (rs) {
                _this.$message({
                  message: '成功撤回工单...',
                  showClose: true,
                  type: 'success'
                })
                _this.getIssuePage()
              } else {
                this.loadingTable = false
              }
            })
        })
        .catch(() => {
          return false
        })
    },
    // 查看
    detailFn: function (item) {
      this.wllzid = item.wllzid
      this.dialogIssuedDetail = true
    },
    dialogIssuedCloseFn: function () {
      this.wllzid = ''
      this.dialogIssuedDetail = false
    }
  },
  components: {
    issuedDetail
  },
  created: function () {
    this.getYearList()
    this.getSourceList()
    this.getDeptList()
    this.doSearch()
  }
}
</script>
